﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace UofCASE.AgileProductLinerDSL.Nant.Tasks.Models
{
    public class TestSet : IEnumerable<ITest>, AspenFSProxy
    {
        internal Platform Powner;
        internal Feature Fowner;
        IList<ITest> tests;

        public TestSet(Platform p, Feature f)
        {
            Powner = p;
            Powner.setFor(this, f);
            Fowner = f;
            Fowner.setFor(this, p);
            tests = new List<ITest>();
        }

        internal void AddTest(ITest t)
        {
            tests.Add(t);
            t.Owner = this;
        }

        public IEnumerator<ITest> GetEnumerator()
        {
            return tests.GetEnumerator();
        }

        internal ITest Find(ITestKey key)
        {
            foreach (ITest test in tests)
            {
                if (key.Matches(test))
                    return test;
            }
            return null;
        }

        public bool Passed
        {
            get
            {
                foreach (ITest t in tests)
                {
                    if(!t.Passed)
                        return false;
                }
                return true;
            }
        }

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return GetEnumerator();
        }

        string AspenFSProxy.PlatformDir
        {
            get { return Powner.PlatformDir(); }
        }

        public string AssemblyPath
        {
            get { return Powner.AssemblyPath; }
        }

        public System.IO.FileInfo CollectionPlan
        {
            get { return Powner.CollectionPlan; }
        }
    }
}
